package com.gaoshi.chapter6;

import javax.swing.*;
import java.time.Instant;
import java.util.Arrays;

/**
 * This program demonstrates the use of lambda expressions.
 */
public class LambdaTest {
    public static void main(String[] args) {
        String[] planets = new String[]{"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"};
        System.out.println(Arrays.toString(planets));
        System.out.println("Sorted in dictionary order:");
        Arrays.sort(planets);
        System.out.println("    " + Arrays.toString(planets));
        System.out.println("Sorted by length:");
        Arrays.sort(planets, (String first, String second) -> first.length() - second.length());
        System.out.println("    " + Arrays.toString(planets));

        var timer = new Timer(1000, (actionEvent) -> System.out.println("The time is " + Instant.ofEpochMilli(actionEvent.getWhen())));
        timer.start();
        JOptionPane.showMessageDialog(null, "Quit program?");
        System.exit(0);
    }
}
